package com.yuandian.management.controller;

import com.yuandian.api.business_monitor.po.SearchParams;
import com.yuandian.api.management.entity.ConfReturnCode;
import com.yuandian.api.management.vo.OptionVo;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.security.annotation.Inner;
import com.yuandian.management.service.*;
import com.yuandian.utils.ListUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 内部接口-Controller
 * @author zfsn
 * @date 2023-3-28
 */
@RestController
@RequestMapping("/innerInterface")
public class InnerController {

	@Autowired
	private ConfBusinessHallService confBusinessHallService;
	@Autowired
	private ConfExclusiveIndicatorService confExclusiveIndicatorService;
	@Autowired
	private ConfEmployeeService confEmployeeService;
	@Autowired
	private ConfMenuMappingService confMenuMappingService;
	@Autowired
	private IOptionService optionService;
	@Autowired
	private ConfReturnCodeService confReturnCodeService;
	@Autowired
	private ConfStepService confStepService;

	/**
	 * 指定地区下的营业厅
	 * @param searchParams 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "指定地区下的营业厅", notes = "指定地区下的营业厅")
	@PostMapping("/getBusinessHall")
	@Inner
	public R<List<Map<String, String>>> getBusinessHall(@RequestBody SearchParams searchParams){
		return R.ok(confBusinessHallService.getBusinessHall(searchParams));
	}

	/**
	 * 查询营业厅信息并装换成 Map<营业厅编码， 营业厅名称>
	 *
	 * @param searchParams 业务编码集合
	 * @return 搜索选项vo对象集合
	 */
	@ApiIgnore
	@Inner
	@PostMapping("/getBusinessHallMap")
	public R<Map<String, String>> getBusinessHallMap(@RequestBody SearchParams searchParams){
		return R.ok(confBusinessHallService.getBusinessHallMap(searchParams));
	}

	/**
	 * 根据营业厅名称列表获取营业厅Id列表
	 *
	 * @param businessHallName
	 * @return 搜索选项vo对象集合
	 */
	@ApiIgnore
	@Inner
	@PostMapping("/getBusinessHallIdListByHallNameList")
	public R<List<String>> getBusinessHallIdListByHallNameList(String businessHallName) {
		return R.ok(confBusinessHallService.getBusinessHallIdListByHallNameList(businessHallName));
	}
	@ApiIgnore
	@Inner
	@GetMapping("/getBusinessHallIdListByHallNameList")
	public R<List<String>> getBusinessHallIdListByHallNameListCopy(String businessHallName) {
		return R.ok(confBusinessHallService.getBusinessHallIdListByHallNameList(businessHallName));
	}
	/**
	 * 组装需要展示的字段(需求886-20220510)
	 * @param map 有序的 LinkedHashMap
	 * @return
	 */
	@ApiIgnore
	@Inner
	@PostMapping("/assemblyDisplayField")
	@ApiOperation(value = "组装需要展示的字段", notes = "组装需要展示的字段")
	public Map<String, Object> assemblyDisplayField(@RequestBody Map<String, Object> map) {
		return confExclusiveIndicatorService.assemblyDisplayFieldInner(map);
	}

	/**
	 * 查询营业员信息并装换成 Map<操作员ID， 操作员名称>
	 *
	 * @param params 业务编码集合
	 * @return 搜索选项vo对象集合
	 */
	@ApiIgnore
	@Inner
	@PostMapping("/getOperatorMap")
	public Map<String, String> getOperatorMap(@RequestBody SearchParams params) {
		return confEmployeeService.getOperatorMap(params);
	}
	/**
	 * 根据操作员列表获取操作员Id列表
	 *
	 * @param operatorName
	 * @return 搜索选项vo对象集合
	 */
	@ApiIgnore
	@Inner
	@PostMapping("/{operatorName}")
	public R<List<String>> getOperatorIdListByOperatorNameList(@PathVariable("operatorName") String operatorName){
		return R.ok(confEmployeeService.getOperatorIdListByOperatorNameList(operatorName));
	}
	/**
	 * 远程调用接口
	 * 查询菜单并装换成 Map<菜单ID, 菜单名称>
	 *
	 * @param params
	 * @return 搜索选项vo对象集合
	 */
	@ApiIgnore
	@Inner
	@PostMapping("/getMenuMap")
	public Map<String, String> getMenuMap(@RequestBody SearchParams params) {
		if (Objects.isNull(params)) {
			params = new SearchParams();
		}

		return confMenuMappingService.getMenuMap(params);
	}
	/**
	 *	查询菜单映射关系
	 * @return 统一响应
	 */
	@ApiIgnore
	@Inner
	@GetMapping("/buttonMap")
	public R<List<OptionVo>> getButtonMap() {
		return R.ok(optionService.getButtonMap());
	}

	/**
	 * 获取返回码信息
	 * @param confReturnCode 实例对象
	 * @return 通用返回对象
	 */
	@Inner
	@ApiOperation(value = "获取返回码信息", notes = "获取返回码信息")
	@PostMapping("/getCodeDetail")
	public R<List<ConfReturnCode>> getCodeDetail(@RequestBody ConfReturnCode confReturnCode) {
		return R.ok(confReturnCodeService.getCodeDetail(confReturnCode));
	}
	/**
	 * 查询业务步骤类型
	 * @return 通用返回对象
	 */
	@ApiIgnore
	@Inner
	@ApiOperation(value = "查询业务步骤类型", notes = "查询业务步骤类型")
	@GetMapping("/queryStepTypeByBusinessCode")
	public R<Map<String,String>> queryStepTypeByBusinessCode(){
		return R.ok(confStepService.queryStepTypeByBusinessCode());
	}
}
